package com.task.manager.service.home.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.task.manager.domain.Actuator;
import com.task.manager.domain.Task;
import com.task.manager.mapper.ActuatorMapper;
import com.task.manager.service.home.ActuatorService;
import com.task.manager.util.TaskUtil;

@Service
public class ActuatorServiceImpl implements ActuatorService {
	
	private static final Logger logger = LoggerFactory.getLogger(ActuatorServiceImpl.class);

	@Autowired
	private ActuatorMapper actuatorMapper;	
	
	@Override
	public List<Actuator> queryActuatorByParam(String actuatorCode, String actuatorName) {
		Actuator record = new Actuator();
		if (!StringUtils.isEmpty(actuatorCode) || !StringUtils.isEmpty(actuatorName)) {
			record.setActuatorCode(TaskUtil.convertEmptyStringToNull(actuatorCode));
			record.setActuatorName(TaskUtil.convertEmptyStringToNull(actuatorName));
			List<Actuator> actuators = actuatorMapper.queryActuatorByParam(record);
			return actuators;
		} else {
			List<Actuator> actuators = actuatorMapper.queryAll();
			return actuators;
		}
	}

	@Override
	public Boolean insertActuator(Actuator actuator) {
		try {
			int i = actuatorMapper.insert(actuator);
			return i == 1;
		} catch (Exception e) {
			logger.error("ActuatorServiceImpl_insertActuator_error:" + e.getMessage(), e);
		}

		return false;
	}

	@Override
	public Boolean updateActuator(Actuator actuator) {
		try {
			int i = actuatorMapper.updateByPrimaryKey(actuator);
			return i == 1;
		} catch (Exception e) {
			logger.error("ActuatorServiceImpl_updateActuator_error:" + e.getMessage(), e);
		}

		return false;
	}

	@Override
	public Boolean deleteActuator(Integer id) {
		try {
			int i = actuatorMapper.deleteByPrimaryKey(id);
			return i == 1;
		} catch (Exception e) {
			logger.error("ActuatorServiceImpl_deleteActuator_error:" + e.getMessage(), e);
		}

		return false;
	}

	@Override
	public List<Actuator> queryAll() {
		return actuatorMapper.queryAll();
	}

}
